package com.thebox.util.config;

import org.apache.commons.digester.*;
import org.apache.commons.digester.xmlrules.*;

import java.io.*;

import com.thebox.config.*;

public class XmlRuleDriver {
    public static void main(String[] args) {
        if (args.length != 2) {
            print("XmlRuleDriver input rules");
            return;
        }

        try {
            File input = new File(args[0]);
            File rules = new File(args[1]);

            //print("input path: " + input.getPath());
            String inputPath = input.getAbsoluteFile().getParent();
            print("input path parent: " + inputPath);
            String rulesPath = rules.getAbsoluteFile().getParent();
            print("rules path parent: " + rulesPath);

            Digester digester = DigesterLoader.createDigester(rules.toURI().toURL());

            //MainConfig mc = (MainConfig)digester.parse(input);
            //mc.setPath(inputPath, rulesPath);
            //mc.loadModule();
            //print(mc.toString());

            //BoxConfig bc = (BoxConfig)digester.parse(input);
            //print(bc.toString());

            ModuleConfig moc = (ModuleConfig)digester.parse(input);
            moc.init();
            print(moc.toString());
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }

    public static void print(Object obj) {
        System.out.println(obj);
    }
}
